using System;
using THANHTUNGO.Portal.Components.Security;
using THANHTUNGO.Portal.Components.Settings;
using THANHTUNGO.Portal.Components.UI;

namespace THANHTUNGO.Portal.Admin
{
    public partial class SiteSetting : PortalModuleControl
    {
        protected override void OnInit(EventArgs e)
        {
            if (!PortalSecurity.IsInRole("1"))
            {
                btnApply.Enabled = PortalSecurity.HasEditPermission(this.ModuleID);
            }

            base.OnInit(e);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                PortalSettings portalSettings = (PortalSettings) Context.Items["PortalSettings"];
                txtSiteName.Text = portalSettings.Name;
                chkShowEditButton.Checked = portalSettings.AlwaysShowEditButton;
                txtLanguage.Text = portalSettings.Language;
                chkAllowRegister.Checked = portalSettings.AllowRegister;
            }
        }

        protected void btnApply_Click(object sender, EventArgs e)
        {
            PortalSettings portalSettings = (PortalSettings) Context.Items["PortalSettings"];
            Configuration config = new Configuration();
            config.UpdatePortalInfo(portalSettings.ID, txtSiteName.Text, chkShowEditButton.Checked, txtLanguage.Text, chkAllowRegister.Checked);
            // Refresh.
            Response.Redirect(Request.RawUrl);
        }
    }
}